<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/facelets/template.xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="title">#{x['faces.label.title.registry.profile']}</ui:define>

	<ui:define name="menu">
		<ui:include src="/facelets/user/userMenu.xhtml" />
	</ui:define>

	<ui:define name="content">

		<h:form id="profileForm" prependId="false">

			<p:growl id="msgs" showDetail="true" showSummary="false"
				autoUpdate="true" />

			<p:panel id="profileSearchPanel">

				<p:focus for="profileName" />

				<h:panelGrid id="profilefieldsGrid" columns="3" cellpadding="5">
					<h:outputLabel for="inputName"
						value="#{x['faces.label.field.name.profile.registry']}: " />
					<p:inputText id="inputName" value="#{profileManager.name}"
						title="#{x['faces.label.field.name.profile.registry']}: " />
					<p:commandButton action="#{profileManager.search()}"
						icon="ui-icon ui-icon-search"
						title="#{x['faces.button.label.generic.search.action']}"
						value="#{x['faces.button.label.generic.search.action']}"
						update=":profileForm:profileDataTable" process="profilefieldsGrid">
					</p:commandButton>
				</h:panelGrid>

				<p:spacer height="12px" />

				<p:dataTable id="profileDataTable" var="profile"
					value="#{profileManager.profiles}" paginator="true" rows="7">

					<p:column>
						<f:facet name="header">
							<h:outputText
								value="#{x['faces.label.field.name.profile.registry']}" />
						</f:facet>
						<h:outputText value="#{profile.name}" />
					</p:column>

					<p:column style="width:70px">
						<f:facet name="header">
							<h:outputText value="#{x['faces.label.generic.action']}" />
						</f:facet>

						<p:commandButton id="editButton" icon="ui-icon ui-icon-pencil"
							title="#{x['faces.button.generic.edit']}" oncomplete="dlg.show()"
							action="#{profileManager.edit(profile)}" process="@this"
							immediate="true"
							update=":profileForm:profileEditDialog, :profileForm:buttonsGrid">
							<f:actionListener
								type="br.com.carser.listeners.CleanFormListener" />
						</p:commandButton>


						<p:commandButton id="excludeButton"
							action="#{profileManager.delete()}" icon="ui-icon ui-icon-trash"
							title="#{x['faces.button.generic.exclude']}" process="@this"
							update="@form" immediate="true">
							<f:setPropertyActionListener for="excludeButton"
								target="#{profileManager.profile}" value="#{profile}" />
						</p:commandButton>
					</p:column>

				</p:dataTable>

				<h:panelGrid columns="1" cellpadding="5">
					<p:commandButton value="#{x['faces.button.generic.new']}"
						action="#{profileManager.reset()}" oncomplete="dlg.show()"
						icon="ui-icon ui-icon-plus"
						title="#{x['faces.buttin.generic.add']}" process="@this"
						update=":profileForm:profileEditGrid, :profileForm:buttonsGrid">
						<f:actionListener type="br.com.carser.listeners.CleanFormListener" />
					</p:commandButton>
				</h:panelGrid>

			</p:panel>


			<p:dialog id="profileEditDialog"
				header="#{x['faces.label.title.registry.profile']}"
				resizable="false" modal="true" widgetVar="dlg">

				<p:focus for="profileName" />

				<h:panelGrid id="profileEditGrid" columns="2" cellpadding="5">

					<h:outputLabel for="profileName"
						value="#{x['faces.label.field.profile.name']}: " />
					<p:inputText id="profileName"
						title="#{x['faces.label.field.profile.name']}"
						requiredMessage="#{x['faces.message.error.required.profile.name']}"
						value="#{profileManager.profile.name}" required="true" />

					<h:outputText
						value="#{x['faces.label.field.profile.permissions']}: " />

					<p:selectManyCheckbox id="permissionList"
						value="#{profileManager.selectedPermissions}"
						layout="pageDirection">
						<f:selectItems value="#{profileManager.permissions}"
							var="permission" itemValue="#{permission}"
							itemLabel="#{permission.description}" />
					</p:selectManyCheckbox>

				</h:panelGrid>

				<h:panelGrid id="buttonsGrid" columns="6" cellpadding="5">
					<p:commandButton value="#{x['faces.button.label.generic.reset']}"
						type="reset" title="#{x['faces.button.label.generic.reset']}" />
					<p:commandButton type="button" onclick="dlg.hide()"
						value="#{x['faces.button.label.generic.cancel']}"
						rendered="#{!profileManager.saved}" />
					<p:commandButton action="#{profileManager.save()}"
						rendered="#{!profileManager.saved}"
						value="#{x['faces.button.label.generic.save']}" process="@form"
						update="@this, :profileForm:buttonsGrid" />
					<p:commandButton type="button" onclick="dlg.hide()"
						value="#{x['faces.button.generic.close']}"
						rendered="#{profileManager.saved}" />
				</h:panelGrid>

			</p:dialog>

		</h:form>

	</ui:define>

</ui:composition>